package com.dy.lock.screen.component.impl;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;

import com.dy.lock.screen.component.TestComponent;
import com.dy.lock.screen.pojo.Test;
import com.dy.lock.screen.scoket.Head;
import com.dy.lock.screen.service.TestService;
import com.dy.lock.screen.utils.CommonUtil;
import com.dy.lock.screen.utils.IDGenerater;
import com.google.gson.Gson;

@Component("testComponent")
public class TestComponentImpl implements TestComponent {

	private static final Logger log = Logger.getLogger(TestComponentImpl.class);
	private Gson gson;
	@Resource(name = "testService")
	private TestService testService;

	public TestComponentImpl() {
		gson = CommonUtil.gson();
	}

	@Override
	public boolean save(String body, Head head) {
		// 调用数据库dao层，执行sql
		// 先把json转 成对应的对象
		Test t = gson.fromJson(body, Test.class);
		// 获取相应数据，执行其他业务逻辑
		this.testService.save(t, head);
		System.out.println(IDGenerater.getInstance()
				.getOrderNo("OrderIdServer"));
		log.info("id:" + t.getId() + ",name:" + t.getName());
		return true;
	}

}
